package com.lai.qq.admin.biz.controller;


import com.alibaba.fastjson.JSON;
import com.lai.qq.admin.biz.req.AutoStyleReq;
import com.lai.qq.admin.biz.res.RebackInfoResult;
import com.byd.dilink.db.vehicle.api.entity.AutoStyle;
import com.byd.dilink.db.vehicle.api.service.AutoStyleDbService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@Slf4j
@RequestMapping("/api/admin/autoStyle")
@RestController
@Api(tags = "款式模块")
public class AutoStyleController {

    @Reference
    private AutoStyleDbService autoStyleDbService;


    @PostMapping("/selectAutoStyle")
    public RebackInfoResult selectAutoStyle(@RequestBody AutoStyleReq req) throws Exception {
        log.info("/autoStyle/selectAutoStyle,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        AutoStyle data = autoStyleDbService.selectOne(param);
        return new RebackInfoResult().success(data);
    }

    @PostMapping("/selectAutoStyleList")
    public RebackInfoResult selectAutoStyleList(@RequestBody AutoStyleReq req) throws Exception {
        log.info("/autoStyle/selectAutoStyleList,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        List<AutoStyle> list = autoStyleDbService.selectListByAutoStyle(param);
        return new RebackInfoResult().success(list);
    }

    @PostMapping("/insertAutoStyle")
    public RebackInfoResult insertAutoStyle(@RequestBody @Validated  AutoStyleReq req ,BindingResult bindingResult) throws Exception {
        log.info("/autoStyle/insertAutoStyle,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        int count =  autoStyleDbService.insert(param);
        if(count!=1){
            return new RebackInfoResult().failure();
        }
        return new RebackInfoResult().success();
    }

    @PostMapping("/updateAutoStyle")
    public RebackInfoResult updateAutoStyle(@RequestBody @Validated AutoStyleReq req, BindingResult bindingResult) throws Exception {
        log.info("/autoStyle/updateAutoStyle,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        int count = autoStyleDbService.updateByPrimaryKey(param);
        if(count!=1){
            return new RebackInfoResult().failure();
        }
        return new RebackInfoResult().success();
    }

    @PostMapping("/deleteAutoStyle")
    public RebackInfoResult deleteAutoStyle(@RequestBody AutoStyleReq req) throws Exception {
        log.info("/autoStyle/deleteAutoStyle,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        int count = autoStyleDbService.delete(param);
        if(count!=1){
            return new RebackInfoResult().failure();
        }
        return new RebackInfoResult().success();
    }

    @PostMapping("/insertToMongoDb")
    public RebackInfoResult insertToMongoDb(@RequestBody @Validated AutoStyleReq req, BindingResult bindingResult) throws Exception {
        log.info("/autoStyle/insertToMongoDb,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        int count =  autoStyleDbService.insertToMongoDb(param);
        if(count!=1){
            return new RebackInfoResult().failure();
        }
        return new RebackInfoResult().success();
    }

    @PostMapping("/updateToMongoDb")
    public RebackInfoResult updateToMongoDb(@RequestBody @Validated AutoStyleReq req, BindingResult bindingResult) throws Exception {
        log.info("/autoStyle/updateToMongoDb,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        int count = autoStyleDbService.updateToMongoDb(param);
        if(count!=1){
            return new RebackInfoResult().failure();
        }
        return new RebackInfoResult().success();
    }

    @PostMapping("/deleteToMongoDb")
    public RebackInfoResult deleteToMongoDb(@RequestBody AutoStyleReq req) throws Exception {
        log.info("/autoStyle/deleteToMongoDb,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        int count = autoStyleDbService.deleteToMongoDb(param);
        if(count!=1){
            return new RebackInfoResult().failure();
        }
        return new RebackInfoResult().success();
    }

    @PostMapping("/selectOneToMongoDb")
    public RebackInfoResult selectToMongoDb(@RequestBody AutoStyleReq req) throws Exception {
        log.info("/autoStyle/selectOneToMongoDb,req={}", JSON.toJSONString(req));
        AutoStyle param = new AutoStyle();
        BeanUtils.copyProperties(req,param);
        AutoStyle data = autoStyleDbService.selectOneToMongoDb(param);
        return new RebackInfoResult().success(data);
    }

}
